package com.desheng.bigdata.flink.stream.transformation

import org.apache.flink.streaming.api.scala._

/**
  * flink对dataset和datastram的分组操作进行的严格的api分离
  * 在dataset中使用groupby
  * 在datastream中使用keyby
  */
object _05Transformation4KeyByOps {
    def main(args: Array[String]): Unit = {
        val env = StreamExecutionEnvironment.getExecutionEnvironment
        env.setParallelism(1)
        val scores = env.fromCollection(List(
            Score(20, "语文", 80),
            Score(30, "数学", 70.5),
            Score(10, "英语", 30.5),
            Score(40, "体育", 60),
            Score(105, "体育", 100),
            Score(106, "英语", 56),
            Score(107, "英语", 42),
            Score(108, "英语", 66),
            Score(109, "语文", 56)
        ))

        val keyed = scores.keyBy(score => score.course)
        keyed.max("score").print()
        env.execute(s"${_05Transformation4KeyByOps.getClass.getSimpleName}")
    }
}
